<template>
	<div id="editmy">
		<div class="img">
			<span>我的头像</span>
			<img :src="userInfo.headimgurl" >
		</div>
		<div class="phone">
			<div style="display: flex;justify-content: space-between;">
				<span>昵称</span>
				<span style="color:#969696;">{{userInfo.nickname}}</span>
			</div>
		</div>
		<div class="sex">
			<span>性别</span>
			<span class="right">{{userInfo.sex}}</span>
		</div>
		<div class="live">
			<span >常住地</span>
			<span class="right">{{userInfo.address}}</span>
		</div>
		<div class="account">
			<span>账号</span>
			<span class="right">{{userInfo.uid}}</span>
			<button class="btnSex" :data-clipboard-text="userInfo.uid">复制</button>
		</div>
		<button class="exit" @click="exit(1)">
			<img src="https://khh-server.oss-cn-beijing.aliyuncs.com/resourse/IMG/static/refresh.png">
			同步微信信息
		</button>
		<v-alert v-if="alertshow" :context="context"></v-alert>
	</div>
</template>

<script>
	import config from "../config/config.js";
	import alert from "../alert.vue";
	import share from "../share/share.js";
    import Clipboard  from 'clipboard/dist/clipboard.js';
	export default{
		components:{
			"v-alert":alert
		},
		data(){
			return {
				alertshow: false,
				context: "",
                userInfo:{}
			}
		},
		methods:{
			exit(){
              var _self=this;
              var value=JSON.stringify({"token":localStorage.getItem('token')}),
                key=demo(value);
              axios.post('/Home/member/UpdateMemberInfo',{
                value:value,
                key:key
              },config)
                .then(function(response) {
                  if(response.data.code==200){
                    this.userInfo=response.data.data;
                  }else{
                    this.userInfo=response.data.data;
                    this.context='刷新成功';
                    _self.alertshow=true;
                    setTimeout(()=>{
                      _self.alertshow=false;
                    },1000)
                  }
                }.bind(this))
                .catch(function (error) {
                  console.log(error);
                });
            },
          GetMemberInfo(){
            var _self=this;
            var value=JSON.stringify({"token":localStorage.getItem('token')}),
              key=demo(value);
            axios.post('/Home/member/GetMemberInfo',{
              value:value,
              key:key
            },config)
              .then(function(response) {
                if(response.data.code==200){
                  this.userInfo=response.data.data;
                }else{
                  this.userInfo=response.data.data;
                  this.context='刷新成功';
                  _self.alertshow=true;
                  setTimeout(()=>{
                    _self.alertshow=false;
                  },1000)
                }
              }.bind(this))
              .catch(function (error) {
                console.log(error);
              });
          },
			},
	  mounted(){
        var that=this;
        const clipboard = new Clipboard('.btnSex');
        clipboard.on('success', function(e) {
          that.alertshow=true;
          that.context='复制成功';
          setTimeout(()=>{that.alertshow=false},2000)
          e.clearSelection();
        });
	  },
      activated(){
        this.GetMemberInfo();
        share({});
		}
	}
</script>

<style>
</style>